'''
Created on 2011-5-2

@author: edison
'''

import base
#import filterTags


class TaoBaoItem(base.TaoBaoAPI):
    
    def setNumiid(self,num):
        self.setParam('num_iid', num)
    
    def getItem(self,num):
        num = str(num)
        self.setMethod('taobao.item.get')
#        self.setParam('fields', 'detail_url,num_iid,title,nick,type,cid,seller_cids,props,input_pids,input_str,desc,pic_url,num,valid_thru,list_time,delist_time,stuff_status,location,price,post_fee,express_fee,ems_fee,has_discount,freight_payer,has_invoice,has_warranty,has_showcase,modified,increment,approve_status,postage_id,product_id,auction_point,property_alias,item_img,prop_img,sku,video,outer_id,is_virtual')
        self.setParam('fields', 'detail_url,num_iid,title,nick,type,cid,seller_cids,props,input_pids,input_str, \
						pic_url,num,valid_thru,list_time,delist_time,stuff_status,location,price,post_fee,express_fee, \
						ems_fee,has_discount,freight_payer,has_invoice,has_warranty,has_showcase,modified,increment,approve_status, \
						postage_id,product_id,auction_point,property_alias,item_img,prop_img,sku,video,outer_id,is_virtual')
        self.setNumiid(num)
        self.sign()
        return self.request()

if __name__ == '__main__':
    import json
    taobao = TaoBaoItem()
    string = taobao.getItem(num = 10089704548)

#    print string 
    string = unicode(string).replace('@', '')

    dict = {}
    try:
        dict = json.loads(string)
    except Exception,e:
        print "Error %s" % e
        exit()
    print dict
    print "=================================================="
    item = dict['item_get_response']['item']
    print item['cid']
    print item['title']
    print item['price']
    print item['stuff_status']
    print item['list_time']
    print item['delist_time']
    print item['detail_url']
    if (item['location']['state'] == item['location']['city']) :
        print item['location']['city']
    else:
        print item['location']['state'],item['location']['city']

